/**
 * 
 */
package com.newtribe.loader;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;

/**
 * @author newtribe
 *
 */
public class Bootstrap {
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		
		String userDir =System.getProperty("user.dir") ;
		File commonDir =new File(userDir+"/lib") ;
		File serverDir =new File(userDir+"/lib2") ;

		File[] commonResource =commonDir.listFiles() ;
		File[] serverResource =serverDir.listFiles() ;
		
		//push lib and configed resource to classloader .
	
		  URL[] urls =new URL[commonResource.length] ;
		  
		  
		  for(int i =0 ;i<commonResource.length;i++) {
			//  String path ="file://"+commonDir.getCanonicalPath()+File.separator+commonResource[i];
			  URL path =commonResource[i].toURI().toURL();
			  System.out.println(path);
			  urls[i] =path;
		  
		  }
		  
		  ExternalFileClassLoader loader =new ExternalFileClassLoader(urls ) ;
		  
		  for(int i =0 ;i<serverResource.length;i++) {
			//  String path ="file://"+serverDir.getCanonicalPath()+File.separator+serverResource[i];
			  URL path =serverResource[i].toURI().toURL();
			  System.out.println(path);
			  loader.addURL(path) ;
		  
		  }

		  //loader.addURL(new URL("file:///"+userDir+"/bin/"));
		 String bootClass="com.newtribe.net.UDPServerChannel" ;
		 URL[] urlss = loader.getURLs();
		// Class clazz =	loader.loadClass("com.newtribe.security.cert.ManagedStarer" ,true) ;
		 Class clazz =	loader.loadClass(bootClass ,true) ;
		 Object starter =clazz.newInstance();
		 Method method= clazz.getMethod("doStart", null) ;
		// ManagedStarer starter =(ManagedStarer)clazz.newInstance();
		 
		 method.invoke(starter,null);
	 
	}
	
	

}
